package com.zengqingfa.juc.n3;

import lombok.extern.slf4j.Slf4j;

/**
 * @author zengqingfa
 * @className TestJoin
 * @description
 * @create 2021/6/7 22:24
 */
@Slf4j(topic = "c.TestJoin")
public class TestJoin2 {
    static int r1 = 0;
    static int r2 = 0;

    public static void main(String[] args) throws Exception {
        test2();
    }

    private static void test2() throws Exception {
        Thread t1 = new Thread(() -> {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            r1 = 10;
        });
        Thread t2 = new Thread(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            r2 = 20;
        });
        long start = System.currentTimeMillis();
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        long end = System.currentTimeMillis();
        log.debug("r1: {} r2: {} cost: {}", r1, r2, end - start);
    }
}